home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / µSim 1.0.5 / FabLibsƒ / CursorBalloon.c < prev    next >
Encoding:
Text File  |  1995-10-24  |  5.6 KB  |  206 lines  |  [TEXT/CWIE]

  1. /*
  2. Copyright © 1993,1994 by Fabrizio Oddone
  3. ••• ••• ••• ••• ••• ••• ••• ••• ••• •••
  4. This source code is distributed as freeware: you can copy, exchange, modify this
  5. code as you wish. You may include this code in any kind of application: freeware,
  6. shareware, or commercial, provided that full credits are given.
  7. You may not sell or distribute this code for profit.
  8. */
  9.  
  10. //#pragma load "MacDump"
  11.  
  12.  
  13. #include    "UtilsSys7.h"
  14. #include    "CursorBalloon.h"
  15. #include    "FabWList.h"
  16.  
  17. static void myShowBalloon(RgnHandle theGlobalCoordsRgn,
  18.                             unsigned long theBalloon,
  19.                             short variant);
  20.  
  21. /* globals for the manager */
  22.  
  23. RgnHandle    mouseRgn, wideOpenRgn;
  24.  
  25. /*
  26. The window will "remember" an object; you pass the following characteristics:
  27. •    the region enclosing the object, in local coordinates;
  28. •    the procedure recalculating the object region (in local coordinates);
  29.     this will be called automatically whenever the window size changes;
  30.     if the object will never be resized, pass nil;
  31.     Here is the prototype for the recalcProc:
  32. void RecalcIO(WindowRef w, RgnBalloonCursPtr theObj);
  33. •    the cursor (B&W) associated with this object;
  34.     if you want the standard arrow cursor, pass nil;
  35. •    the balloon that will appear when Balloon Help is on;
  36.     use this macro: toBalloon(ID_of_STR#_resource, index );
  37.     if you do not want a balloon, pass 0L;
  38. •    the variant of the balloon (see Inside Macintosh for the meaning of this)
  39.     if you do not want a balloon, pass 0;
  40. */
  41.  
  42. OSErr InstallRgnHandler(FabWindowPtr w, RgnHandle whichRgn, void (*recalcProc)(DialogRef, RgnBalloonCursPtr),
  43.                         CursHandle cursor,
  44.                         unsigned long balloon, short ballnVariant, short iID)
  45. {
  46. RgnBalloonCurs    t;
  47. Point    mypt = { 0, 0};
  48. register OSErr err = appMemFullErr;
  49.  
  50. t.recalcRgnProc = recalcProc;
  51. t.zoneLocal = whichRgn;
  52. t.curs = cursor;
  53. t.myBalloon = balloon;
  54. t.balloonVariant = ballnVariant;
  55. t.itemID = iID;
  56. t.zoneGlobal = NewRgn();
  57. if (t.zoneGlobal) {
  58.     LocalToGlobal(&mypt);
  59.     CopyRgn(whichRgn, t.zoneGlobal);
  60.     OffsetRgn(t.zoneGlobal, mypt.h, mypt.v);
  61.  
  62.     if ((err = PtrAndHand(&t, (Handle)Zones(w), sizeof(RgnBalloonCurs))) == noErr)
  63.         OneMoreObject(w);
  64.     }
  65. return err;
  66. }
  67.  
  68. /* Recalculate the mouse region; you pass:
  69. •    a WindowPtr (not necessarily a FabWindowPtr);
  70. •    the mouse position (in global coordinates);
  71. */
  72.  
  73. void RecalcMouseRegion(DialogRef d, Point mouse)
  74. {
  75. FabWindowPtr    thefabw;
  76. register RgnBalloonCursPtr    curObj;
  77. register unsigned long    i;
  78.  
  79. thefabw = GetFabWindowPtr(d);
  80. if (thefabw && NumObjects(thefabw)) {
  81.     CopyRgn(wideOpenRgn, mouseRgn);
  82.     HLockHi((Handle)Zones(thefabw));
  83.     for (i = 1, curObj = *Zones(thefabw); i <= NumObjects(thefabw); i++, curObj++) {
  84.         if (PtInRgn(mouse, curObj->zoneGlobal)) {
  85.             if (curObj->curs)
  86.                 SetCursor(*curObj->curs);
  87.             else
  88.                 SetCursor(&qd.arrow);
  89.             if (curObj->myBalloon)
  90.                 if (HMGetBalloons())
  91.                     myShowBalloon(curObj->zoneGlobal, curObj->myBalloon,
  92.                                     curObj->balloonVariant);
  93.             CopyRgn(curObj->zoneGlobal, mouseRgn);
  94.             break;
  95.             }
  96.         else
  97.             DiffRgn(mouseRgn, curObj->zoneGlobal, mouseRgn);
  98.         }
  99.     if (i > NumObjects(thefabw))
  100.         SetCursor(&qd.arrow);
  101.     HUnlock((Handle)Zones(thefabw));
  102.     }
  103. else {
  104.     CopyRgn(wideOpenRgn, mouseRgn);
  105.     SetCursor(&qd.arrow);
  106.     }
  107. }
  108.  
  109. /* Resizes the dynamic objects of the window by calling the recalcProc
  110. for every object */
  111.  
  112. FabWindowPtr ResizeObjects(DialogRef d)
  113. {
  114. register void (*theProc)(DialogRef, RgnBalloonCursPtr);
  115. register RgnBalloonCursPtr    curObj;
  116. register unsigned long    i;
  117. FabWindowPtr    thefabw;
  118.  
  119. if (thefabw = GetFabWindowPtr(d)) {
  120.     if (NumObjects(thefabw)) {
  121.         HLockHi((Handle)Zones(thefabw));
  122.         for (i = 1, curObj = *Zones(thefabw); i <= NumObjects(thefabw); i++, curObj++) {
  123.             theProc = curObj->recalcRgnProc;
  124.             if (theProc)
  125.                 theProc(d, curObj);
  126.             }
  127.         HUnlock((Handle)Zones(thefabw));
  128.         }
  129.     }
  130. return thefabw;
  131. }
  132.  
  133. /* Calculates the regions for the given FabWindow in global coordinates,
  134. so that they are ready for WaitNextEvent
  135. */
  136.  
  137. void RecalcGlobalCoords(FabWindowPtr w)
  138. {
  139. register RgnBalloonCursPtr    curObj;
  140. register unsigned long    i;
  141. Point    mypt = { 0, 0};
  142.  
  143. if (NumObjects(w)) {
  144.     HLockHi((Handle)Zones(w));
  145.     LocalToGlobal(&mypt);
  146.     for (i = 1, curObj = *Zones(w); i <= NumObjects(w); i++, curObj++) {
  147.         CopyRgn(curObj->zoneLocal, curObj->zoneGlobal);
  148. // -(((WindowPtr)w)->portBits.bounds.left)
  149. // -(((WindowPtr)w)->portBits.bounds.top)
  150.         OffsetRgn(curObj->zoneGlobal, mypt.h, mypt.v);
  151.         }
  152.     HUnlock((Handle)Zones(w));
  153.     }
  154. }
  155.  
  156. /* myShowBalloon: common routine for showing up balloons */
  157.  
  158. static void myShowBalloon(RgnHandle theGlobalCoordsRgn,
  159.                             unsigned long theBalloon, short variant)
  160. {
  161. HMMessageRecord    helpMsg;
  162. Point    myTip;
  163.  
  164. myTip.v = (*theGlobalCoordsRgn)->rgnBBox.top + 3;
  165. myTip.h = (*theGlobalCoordsRgn)->rgnBBox.right - 3;
  166. helpMsg.hmmHelpType = khmmStringRes;
  167. *(unsigned long *)&helpMsg.u.hmmStringRes.hmmResID = theBalloon;
  168. //helpMsg.u.hmmStringRes.hmmIndex = *(((short *)(&theBalloon)) +1);
  169. if (hmBalloonAborted == HMShowBalloon(&helpMsg, myTip, &(*theGlobalCoordsRgn)->rgnBBox,
  170.                                         nil, 0, variant, kHMRegularWindow))
  171.     ForceMouseMovedEvent();
  172. }
  173. /*
  174. void DisposFabWindow(FabWindowPtr w)
  175. {
  176. register RgnBalloonCursHandle    tempH;
  177. register RgnBalloonCursPtr    spanPtr;
  178. register unsigned long    i;
  179.  
  180. tempH = Zones(w);
  181. HLock((Handle)tempH);
  182. spanPtr = *tempH;
  183.  
  184. for (i = 0; i < NumObjects(w); i++, spanPtr++) {
  185.     DisposeRgn(spanPtr->zoneLocal);
  186.     DisposeRgn(spanPtr->zoneGlobal);
  187. // we do nothing with the CursHandles since they might be system cursors
  188.     }
  189. DisposeHandle((Handle)tempH);
  190. // the caller knows whether CloseWindow or CloseDialog is to be called
  191. }
  192.  */
  193. void ForceMouseMovedEvent(void)
  194. {
  195. SetRectRgn(mouseRgn, 32761, 32761, 32765, 32765);
  196. }
  197.  
  198. /*
  199. void InitFabWindow(FabWindowPtr w)
  200. {
  201. Zones(w) = (RgnBalloonCursHandle)NewHandle(0);
  202. if (GetWindowKind(w) != dialogKind)
  203.     SetWindowKind(w, kFabWindowClass);
  204. }
  205. */
  206.